package com.lagou.rpc.consumer.controller;

import com.lagou.rpc.api.IUserService;
import com.lagou.rpc.consumer.proxy.RpcClientProxy;
import com.lagou.rpc.pojo.User;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lihongfeng
 * @date 2021/12/28
 */
@RestController
public class UserController {

    /**
     * 配置controller
     * @param id
     * @return
     */
    @GetMapping(value = "/user/{id}" ,produces = MediaType.APPLICATION_JSON_VALUE )
    public String getUser(@PathVariable("id") String id){
        IUserService userService = (IUserService) RpcClientProxy.createProxy(IUserService.class);
        User user = userService.getById(Integer.parseInt(id));
        return user.toString();
    }
}
